<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Users extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('users',array('engine'=>'InnoDB'));
        $exists = $this->hasTable('users');
        if(!$exists){
            $table
                ->addColumn('parent_id', 'integer',array('limit' => 11,'default'=>'0','comment'=>'邀请人id'))
                ->addColumn('mobile', 'string',array('limit' => 12,'default'=>'0','comment'=>'手机号'))
                ->addColumn('tcoin', 'integer',array('limit' => 8,'default'=>0,'comment'=>'推币'))
                ->addColumn('openid_qq', 'string',array('limit' => 14,'default'=>0,'comment'=>'QQopenid'))
                ->addColumn('openid_wx', 'string',array('limit' => 14,'default'=>0,'comment'=>'微信openid'))
                ->addColumn('openid_wb', 'string',array('limit' => 14,'default'=>0,'comment'=>'微博openid'))
                ->addColumn('invite_code', 'string',array('limit' => 9,'default'=>0,'comment'=>'邀请码'))
                ->addColumn('create_time', 'integer',array('limit' => 11,'default'=>'1563845960','comment'=>'创建时间'))
                ->addIndex(array('mobile'), array('unique' => true))
                ->create();
        }
    }
}
